<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/sys/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>产品追溯二维码</title>
<%@ include file="/WEB-INF/sys/include/css.jsp"%>
</head>
<body>
<form id="form" action="#" method="post" onkeydown="if(event.keyCode==13){return false;}">
<div class="form">
	<div class="group">
		<div class="label">地块名称:</div>
		<div class="text">${products.parkName } / ${products.blockName }</div>
	</div>
	<div class="group">
		<div class="label">产品名称:</div>
		<div class="text" style="width:120px;">${products.pdtname }</div>
		<div class="label">生产日期:</div>
		<div class="text">${qx:fmt(products.endTime, "yyyy-MM-dd")}</div>
	</div>
	<div class="group" style="overflow:hidden;">
		<div class="label">二维码:</div>
		<div class="item">
			<div style="width:220px;height:245px;border:1px solid #999;" align="center">
				<div><img id="qrcodeimg" alt="${products.pbn }" src="${path }/res/img/noimg.jpg" width="200" height="200" style="margin:0px;margin-top:5px;" /></div>
				<div style="height:25px;line-height:16px;font-size:14px;vertical-align:top;text-align:center;">追溯码：${products.pbn }</div>
			</div>
		</div>
	</div>
	<div class="group">
		<div class="label">打印数量:</div>
		<div class="item"><input type="text" id="copyes" value="1" /></div>
	</div>
	<div class="buttons">
		<button class="highlight" id="submit1" type="button">打印</button>
		<button type="button" id="cancel1">返回</button>
	</div>
</div>
</form>
<%@ include file="/WEB-INF/sys/include/script.jsp" %>
<script type="text/javascript">
$(function() {
	$("#form").ligerForm({inputWidth: 222});
	
	$("#submit1").click(function(){
		codePrint();
	});

	$("#cancel1").click(function(){
		UiUtil.closeForm();
	});
	
	$("#view1").click(function(){
		location.herf = '${qrcode_url}';
	});
	
	var codeText = '${qrcode_url}';
	if(codeText != ''){
		$('#qrcodeimg').attr('src', '${path}/public/qrcode.do?size=200&errorCorrect=H&text='+encodeURIComponent(codeText));
	}
});

// TSC M2405打印机
function codePrint(){
	var url = "${qrcode_url}";
	url = url.replace(":80/","/");
	//打印数量
	var copyes = parseInt(jQuery('#copyes').val());
	//产品名称
	var goods = "产品名称："+"${products.pdtname }";
	//产地
	var chanName = "${products.companyName }";
	//追溯码
	var code = "条码信息："+"${products.pbn }";
	var codeV = "${products.pbn }";
	//生产日期
	var scDate = "上市时间："+"${qx:fmt(products.endTime, "yyyy-MM-dd")}";
	//追溯地址
	var qrUrl = url;
	//追溯查询地址
	//var cha = "追溯查询："+url;
	
	
	//测试项
// 	chanName = "山西大宗农业种植有限公司";
// 	code = "条码信息：100601004400062";
// 	scDate = "上市时间：2018-09-27";
// 	qrUrl = "http://m.lfjckj.com:8000/mq/100601004400062";
	//cha = "追溯查询：m.lfjckj.com:8000";
	
	
	var TSCObj;
	TSCObj = new ActiveXObject("TSCActiveX.TSCLIB");
	//显示DLL版本号码
	//TSCObj.ActiveXabout();
	//打印机设备名称
	TSCObj.ActiveXopenport ("Bar Code Printer M-2405");
	TSCObj.ActiveXdownloadpcx ("D:/UL.PCX","UL.PCX");

	//setup(a,b,c,d,e,f,g)   a(设定标签的宽度)  b(高度)  c(打印速度)  d(打印浓度)  e(感应器类别)  f(gap/black mark 垂直间距)  g(gap/black mark 偏移距离)
	TSCObj.ActiveXsetup ("61.6","33.5","5","8","0","2","0");
	//TSCObj.ActiveXformfeed();
	//TSCObj.ActiveXnobackfeed();
	
	//SET TEAR ON/OFF开启或者关闭打印机将纸张送出到间隙或者黑标位置用来撕去
	TSCObj.ActiveXsendcommand ("SET TEAR ON");

	//clearbuffer清除打印机缓存中的图像
	TSCObj.ActiveXclearbuffer();
	//printerfont使用打印机内建字打印
	//TSCObj.ActiveXprinterfont ("10","10","3","0","1","1","ActiveXdll Test!!");
	//sendcommand送内建指令到打印机
	//TSCObj.ActiveXsendcommand ("PUTPCX 10,200,\"UL.PCX\"");
	//TSCObj.ActiveXwindowsfont (65, 45, 32, 0, 0, 0, "Times new Roman", "高平市农产品质量安全追溯");
	TSCObj.ActiveXwindowsfont (210, 80, 20, 0, 2, 0, "Times new Roman", goods);
	//打印认证时间
	TSCObj.ActiveXwindowsfont (210, 110, 20, 0, 2, 0, "Times new Roman", scDate);
	//打印追溯码
	TSCObj.ActiveXwindowsfont (210, 140, 20, 0, 2, 0, "Times new Roman", code);
	if(chanName.length>8){
		var chan = "生产企业："+chanName.substring(0,8);
		TSCObj.ActiveXwindowsfont (210, 170, 20, 0, 2, 0, "Times new Roman", chan);
		var chan1 = chanName.substring(8);
		TSCObj.ActiveXwindowsfont (247, 200, 20, 0, 2, 0, "Times new Roman", chan1);
	}else{
		var chan = "生产企业："+chanName;
		TSCObj.ActiveXwindowsfont (210, 170, 20, 0, 2, 0, "Times new Roman", chan);
	}
	
	//打印二维码
	TSCObj.ActiveXsendcommand ("QRCODE 10,51,M,6,A,0,M2,S2,\""+qrUrl+"\"");
	
	//打印查询地址
	//TSCObj.ActiveXwindowsfont (170, 235, 20, 0, 0, 0, "Times new Roman", cha);
	//打印条码
	//TSCObj.ActiveXbarcode ("100", "40", "128", "50", "1", "0", "2", "2", "123456789");
	
	TSCObj.ActiveXprintlabel (copyes,"1");
	//关闭指定的计算机端输出端口
	TSCObj.ActiveXcloseport();
}
</script>
</body>
</html>